<template>
  <div class="user-header">
    <!-- 用户基本信息栏 -->
    <div class="user-info-bar">
      <div class="user-phone">
        {{ maskPhoneNumber(userPhone) }}
      </div>
      <div class="setting-icon" @click="goToSettings">
        <i class="fa fa-cog"></i>
      </div>
    </div>
    
    <!-- 会员俱乐部横幅 -->
    <div class="member-banner">
      <div class="banner-content">
        <div class="banner-text">
          <span class="icon">悦</span>
          <span>悦享俱乐部 | 高端权益全新上线</span>
        </div>
        <div class="banner-btn">
          去看看
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '../../store/pinia_store_user';

const router = useRouter();
const userStore = useUserStore();

// 获取用户手机号
const userPhone = computed(() => {
  const user = userStore.userInfo;
  return user?.phoneNumber || '未登录';
});

// 手机号码脱敏处理
const maskPhoneNumber = (phone) => {
  if (!phone || phone === '未登录') return '未登录';
  if (phone.length !== 11) return phone;
  
  return phone.substring(0, 3) + '****' + phone.substring(7);
};

// 跳转到设置页面
const goToSettings = () => {
  router.push('/settings');
};
</script>

<style scoped>
.user-header {
  padding: 15px 0;
}

.user-info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  margin-bottom: 15px;
}

.user-phone {
  font-size: 20px;
  font-weight: bold;
  color: #333;
  display: flex;
  align-items: center;
}

.user-phone::before {
  content: '';
  display: inline-block;
  width: 32px;
  height: 32px;
  margin-right: 8px;
  background-color: #a0d8f1;
  border-radius: 50%;
}

.setting-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #666;
}

.member-banner {
  margin: 0 15px;
  background-image: linear-gradient(to right, #f8d0c4, #ffe7e1);
  border-radius: 8px;
  padding: 15px;
}

.banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.banner-text {
  font-size: 14px;
  font-weight: bold;
  color: #6f2b1a;
  display: flex;
  align-items: center;
}

.banner-text .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background-color: #ff6e30;
  color: white;
  border-radius: 5px;
  margin-right: 8px;
  font-size: 12px;
}

.banner-btn {
  padding: 4px 12px;
  background-color: #fff;
  color: #ff6e30;
  font-size: 12px;
  font-weight: bold;
  border-radius: 15px;
}
</style> 